<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\Post\Restore;
use App\Models\StoreGoods;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use App\Admin\Actions\Modal\memberModal;


class GoodsController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new StoreGoods(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('image')->image();
            $grid->column('store_name');
            $grid->column('ot_price');
            $grid->column('sales');
            $grid->column('stock');
            $grid->column('sort');
            $grid->column('is_show');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
            $grid->quickSearch()->placeholder('搜索...',);
            $grid->quickSearch('store_name');
            $grid->filter(function ($filter) {
                $filter->scope('trashed', '商品回收站')->onlyTrashed();
            });
            $grid->export();
            $grid->export()->xlsx();
            $titles = ['id' => 'ID', 'store_name' => '名称', 'ot_price' => '价格'];
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                if (request('_scope_') == 'trashed') {
                    $actions->append(new Restore(StoreGoods::class));
                }
            });

            $grid->tools(function(Grid\Tools $tools)  {
                //Excel导入
                $tools->append(new memberModal());
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new StoreGoods(), function (Show $show) {
            $show->field('id');
            $show->field('image');
            $show->field('store_name');
            $show->field('store_info');
            $show->field('keyword');
            $show->field('cate_id');
            $show->field('price');
            $show->field('ot_price');
            $show->field('postage');
            $show->field('unit_name');
            $show->field('sort');
            $show->field('sales');
            $show->field('stock');
            $show->field('is_show');
            $show->field('is_hot');
            $show->field('is_benefit');
            $show->field('is_best');
            $show->field('is_new');
            $show->field('add_time');
            $show->field('is_postage');
            $show->field('is_del');
            $show->field('cost');
            $show->field('is_seckill');
            $show->field('is_bargain');
            $show->field('is_good');
            $show->field('group_price');
            $show->field('is_groupbooking');
            $show->field('is_sub');
            $show->field('ficti');
            $show->field('browse');
            $show->field('temp_id');
            $show->field('spec_type');
            $show->field('activity');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new StoreGoods(), function (Form $form) {
            $form->display('id');
            $form->file('image')->disk('qiniu');
            $form->text('store_name');
            $form->text('store_info');
            $form->text('keyword');
            $form->text('cate_id');
            $form->text('price');
            $form->text('ot_price');
            $form->text('postage');
            $form->text('unit_name');
            $form->text('sort');
            $form->text('sales');
            $form->text('stock');
            $form->switch('is_show');
            $form->text('is_hot');
            $form->text('is_benefit');
            $form->text('is_best');
            $form->text('is_new');
            $form->text('add_time');
            $form->text('is_postage');
            $form->text('is_del');
            $form->text('cost');
            $form->text('is_seckill');
            $form->text('is_bargain');
            $form->text('is_good');
            $form->text('group_price');
            $form->text('is_groupbooking');
            $form->text('is_sub');
            $form->text('ficti');
            $form->text('browse');
            $form->text('temp_id');
            $form->text('spec_type');
            $form->text('activity');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
